1946A - Median of an Array - CodeForces Solution


implementation

Please click on ads to support us..

Python Code:

t=int(input())

while t>0:
    t-=1
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    if n==1:
        print(1)
    else:
        res=0
        mdx=(n)//2 +n%2-1
        for i in range(mdx,n):
            if a[mdx]==a[i]:
                res+=1
        print(res)


Comments

Submit
0 Comments
More Questions

1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious